﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;

namespace LoL_Profiler
{
    public static class XMLParser
    {
        public static void readFromXML()
        {
            XElement summoners = XElement.Load(@"Data.xml");
        }

        public static void writeToXML(List<Summoner> _summoners)
        {            
            XElement summoners =
            new XElement("summoners",
                from s in _summoners
                select new XElement("summoner",
                    new XAttribute("summonerid", s.SummonerID),
                    new XElement("summonername", s.SummonerName),
                    new XElement("region", s.Region),
                    //new XElement("elo", s.Elo),                    
                    new XElement("matches",
                        from m in s.MatchHistory                   
                        select new XElement("match",
                            new XElement("type", m.Type),
                            new XElement("outcome", m.Outcome),
                            new XElement("kills", m.ownKills),
                            new XElement("deaths", m.ownDeaths),
                            new XElement("assists", m.ownAssists),
                            new XElement("teammembers",
                                from t in m.Team
                                select new XElement("teammember",
                                    new XElement("summonerid", t.SummonerID),
                                    new XElement("summonername", t.SummonerName)
                                )
                            )
                        )
                    )
                )
            );

            summoners.Save("Data.xml");

            //Console.WriteLine(summoners);
        }
    }
}
